package com.itheima.reggie.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.itheima.reggie.common.R;
import com.itheima.reggie.dto.OrdersDto;
import com.itheima.reggie.pojo.OrderDetail;
import com.itheima.reggie.pojo.Orders;
import com.itheima.reggie.service.OrderDetailService;
import com.itheima.reggie.service.OrdersService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@RestController
@RequestMapping("/order")
@Slf4j
public class OrdersController {
    @Autowired
    OrdersService ordersService;
    @Autowired
    OrderDetailService orderDetailService;
    //请求网址: http://localhost:8080/order/submit
    //请求方法: POST
    @PostMapping("/submit")
    public R<String> submit(HttpServletRequest request, @RequestBody Orders order){
        Long userId = (Long) request.getSession().getAttribute("user");
        ordersService.submit(userId,order);
        return R.success("提交订单成功！");
    }
    //请求网址: http://localhost:8080/order/userPage?page=1&pageSize=1
    //请求方法: GET
    @GetMapping("/userPage")
    public R<Page> userPage(int page,int pageSize){
        return ordersService.userPage(page,pageSize);
    }
}
